package cn.fangline.wo.task.akka.actors;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import cn.fangline.base.util.Constants;
import cn.fangline.wo.task.akka.messages.AgentPage;
import java.time.LocalDateTime;

/**
 * Created by 抽离 on 2017/6/21 0021.
 */
public class MasterActor extends AbstractActor {


    private ActorRef agentRef;


    public MasterActor(ActorRef agentRef) {
        this.agentRef = agentRef;
    }

    @Override
    public void preStart() throws Exception {
        super.preStart();
        System.out.println("进入MasterActor了！");
        AgentPage agentPage = new AgentPage();
        agentPage.setUrl("http://xm.anjuke.com/tycoon/");
        agentPage.setCount(Constants.RETRY_COUNT);
        agentPage.setCityId(15);
        agentRef.tell(agentPage, getSelf());
//            Agent agent = new Agent();
//            agent.setAgentName("啦啦啦");
//            try{
//                agent.insert();
//            }catch (Exception e){
//                e.printStackTrace();
//            }
    }

    @Override
    public Receive createReceive() {
        return
                receiveBuilder()
                        .match(AgentPage.class, this::onReceiveAgentPage)
                        .build();
    }

    private void onReceiveAgentPage(AgentPage m) {
        agentRef.tell(m, getSelf());
    }
}
